package com.sunlee.app.api.controller;

import com.sunlee.common.core.entity.PageData;
import com.sunlee.common.core.entity.Result;
import com.sunlee.common.service.dto.ProductDTO;
import com.sunlee.common.service.entity.vo.CategoryVO;
import com.sunlee.common.service.service.CategoryService;
import com.sunlee.common.service.dto.req.CategoryProductDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author sunjulei
 * @date 2022/7/1
 */
@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("all")
    public Result<List<CategoryVO>> getAllCategory() {
        return Result.ok(categoryService.getValidCategoryList());
    }

    @PostMapping("page")
    public Result<PageData<ProductDTO>> getCategoryByIdAndLevel(@Validated @RequestBody CategoryProductDTO request) {
        return Result.ok(categoryService.getCategoryByIdAndLevel(request));
    }
}
